'''
Created on 2009-11-21

@author: wenjinjin@gmail.com
'''

from google.appengine.ext import db

from mod.member import Member
from mod.blog import Blog
from mod.tag import Tag
class Favorite(db.Model):
    '''
    classdocs
    '''

    member = db.ReferenceProperty(Member)
    blog = db.ReferenceProperty(Blog)
    createtime = db.DateTimeProperty(auto_now_add=True)
    
    def add(self,member,blog):
        self.member = member
        self.blog = blog
        if self.notInMyFav() :
            self.put()
            self.blog.incrFavNum()
            return True
        else:
            return False
    def notInMyFav(self):
        query = db.GqlQuery("select * from Favorite where member=:1 and blog = :2" ,self.member,self.blog)
        fav = query.get()
        if fav:
            return False
        else:
            return True